package com.hello.rabbithandler;

import com.Constants;
import com.Emp;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = Constants.QUEUE_NAME)
public class ConsumerRabbitHandler {

    @RabbitHandler()
    public void receive(Emp msg) {
        System.out.println("receive:Thread.currentThread().getName() = " + Thread.currentThread().getName());
        System.out.println("msg(Emp) = " + msg);
    }


    @RabbitHandler
    public void receive2(String msg) {
        System.out.println("receive2:Thread.currentThread().getName() = " + Thread.currentThread().getName());
        System.out.println("msg(String) = " + msg);
    }

    //isDefault=true：没有特定类型对应的接收方法时又此方法处理
    @RabbitHandler(isDefault = true)
    public void receive3(Object msg) {
        System.out.println("receive3:Thread.currentThread().getName() = " + Thread.currentThread().getName());
        System.out.println("msg(object) = " + msg);
    }
}
